#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2017/8/26 下午10:43
# @Author  : Liujiaqi
# @Site    : 
# @File    : ceshiApi.py
# @Software: PyCharm

import logging
from util.Logger import Logger
import requests
import json


logger = Logger('slowLogAgentApi.log',logging.DEBUG,logging.DEBUG)


class PostMysqlSlowLogDataApiClient():

    def __init__(self,url,post_data):
        self.url = url
        self.post_data = post_data

    def post_slow_log_data(self):
        request = requests.post(self.url,self.post_data)
        logger.debug("slow log发送服务器端成功 "+str(request.text))

if __name__ == '__main__':
    list = [{"query_time": "11.000463", "last_errno": "0", "rows_examined": "0", "rows_sent": "1", "timestamp": "1502663349", "fingerprint": "select sleep(?); ", "bytes_sent": "64", "lock_time": "0.000000", "killed": "0", "user": "root", "sql": "select sleep(11); ", "ip": "localhost", "time": "2017-08-14 06:29:09", "schema": "null"}, {"query_time": "10.900634", "rows_examined": "0", "rows_sent": "1", "timestamp": "1502663349", "ip": "localhost", "last_errno": "0", "bytes_sent": "66", "lock_time": "0.000000", "user": "root", "sql": "select sleep(10.9); ", "fingerprint": "select sleep(?); ", "killed": "0", "schema": "zeus"}]
    strList = json.dumps(list)
    postData = {}
    postData['instance_id']=1
    postData['post_data']=strList
    print strList
    a = PostMysqlSlowLogDataApiClient('http://127.0.0.1:5001/agent/getSlowConf',postData)
    print str(__file__)
    print a.url
    print a.post_data
    a.post_slow_log_data()